﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SiteUserMaster : System.Web.UI.MasterPage
{
    string selectedLanguage;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.UserAgent.IndexOf("AppleWebKit") > 0)
        {
            Request.Browser.Adapters.Clear();
        }

        btnLanguage.OnClientClick = "javascript:return confirm('" + Resources.CarInsurance.LanguageChangeMessage + "');";

        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("CXCRMIsCXLive");
        if (_strCXLive == "0")
        {
            if (Session[CE.Global.General.Guest] == null)
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        if (Session[CE.Global.General.ProviderCompanyId] != null)
        {
            imgLogo.Visible = false;
        }
        else if (Session[CE.Global.General.UserId] != null)
        {
            imgLogo.Visible = false;
            DateTime _dtLastLoginTime = Convert.ToDateTime(Session[CE.Global.General.LastLoginTime].ToString());
            divProviderInfo.InnerHtml = Resources.General.Welcome + Session[CE.Global.General.UserName].ToString() + ", GG CRM - Teledirect Thailand<br /><span>" + Resources.General.LastLoginDateTime + " : " + _dtLastLoginTime.ToShortDateString() + " " + _dtLastLoginTime.ToShortTimeString() + "</span>";
            litTitlePage.Text = "GG-CRM - กล้วยๆ.com - Teledirect Thailand";
            hplLogInOut.Text = Resources.General.SignOut;
            hplChangePassword.Visible = false;
            hplLogInOut.NavigateUrl = "~/User/Logout.aspx";
            hplLogInOut.Attributes.Add("onclick", "javascript:return confirm('" + Resources.General.ConfirmSIGNOUTMessage + "')");
        }
        DateTime time = CE.Global.General.GetUTCDateTime();
        lblTodayDate.Text = Resources.General.Date + ":" + time.ToString("dddd") + " ";
        lblTodayDate.Text += time.ToString("dd-MMMM-yyyy");
        lblTodayDate.Font.Bold = true;

    }


    protected void btnLanguage_Click(object sender, EventArgs e)
    {
        selectedLanguage = string.Empty;

        if (lblLanguage.Text != string.Empty)
        {
            Session["Language"] = lblLanguage.Text;
        }

        if (Session["Language"] != null)
        {
            selectedLanguage = Session["Language"].ToString();
        }
        else
        {
            selectedLanguage = "th-TH";
            Session["Language"] = selectedLanguage;
        }

        if (selectedLanguage == "th-TH")
        {
            Session["Language"] = "en-US";
        }
        else
        {
            Session["Language"] = "th-TH";
        }

        lblLanguage.Text = selectedLanguage;

        Response.Redirect(Request.UrlReferrer.AbsoluteUri);
    }
}
